//package com.wangnaiqi.pulsar.config;
//
//import com.wangnaiqi.pulsar.entidy.User;
//import com.wangnaiqi.pulsar.service.Consumer2Service;
//import com.wangnaiqi.pulsar.service.Consumer3Service;
//import com.wangnaiqi.pulsar.service.ConsumerService;
//import org.apache.pulsar.client.api.*;
//import org.apache.pulsar.client.impl.schema.BytesSchema;
//import org.apache.pulsar.client.impl.schema.JSONSchema;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.PostConstruct;
//
///**
// * @author wangnaiqi
// * @description TODO
// * @date 2023/12/13
// */
//@Configuration
//public class PulsarConsumerConfig {
//    @Autowired
//    PulsarClient pulsarClient;
//
//    @Value("${pulsar.consumer.name.test-consumer-name}")
//    String consumerName;
//
//    @Value("${pulsar.topic.name.test-topic-name}")
//    String topicName;
//
//    @Value("${pulsar.subscription.name.test-subscription-name}")
//    String subscriptionName;
//
//    @Value("${pulsar.consumer.name.test2-consumer-name}")
//    String consumerName2;
//
//    @Value("${pulsar.topic.name.test2-topic-name}")
//    String topicName2;
//
//    @Value("${pulsar.subscription.name.test2-subscription-name}")
//    String subscriptionName2;
//
//    @Autowired
//    private ConsumerService consumerService; // 注入MessageHandler实例
//
//    @Autowired
//    private Consumer2Service consumer2Service; // 注入MessageHandler实例
//
//    @Autowired
//    private Consumer3Service consumer3Service; // 注入MessageHandler实例
//
//    public <T> Consumer<T> getConsumer(String topicName, String subscriptionName, String consumerName, SubscriptionInitialPosition subscriptionInitialPosition, Schema<T> schema, MessageListener<T> messageListener) {
//        Consumer<T> pulsarConsumer = null;
//
//        ConsumerBuilder<T> consumerBuilder = pulsarClient.newConsumer(schema)
//                .topic(topicName)
//                .subscriptionName(subscriptionName)
//                .subscriptionType(SubscriptionType.Shared)
//                .subscriptionInitialPosition(subscriptionInitialPosition)
//                .messageListener(messageListener)
//                .consumerName(consumerName);
//        try {
//            pulsarConsumer = consumerBuilder.subscribe();
//        } catch (PulsarClientException e) {
//            e.printStackTrace();
//        }
//        return pulsarConsumer;
//    }
//}
